// 引入模块
let express = require("express")

// 使用router
let router = express.Router();
// 引用fs
let fs=require("fs")

// 引入json文件
let json =fs.readFileSync(__dirname+"/persons.json","utf8")

let ojson = JSON.parse(json);

// console.log(ojson);
// 规划路由
router.get('/log', (req, res) => { 
    res.render('../views/login.html')

})

// 获取表单输入的数据
router.post('/log', (req, res) => { 
    // 判断
    let { tel, pass,pass1,yanzheng} = req.body    
    console.log(tel, pass);
    let p = ojson.find((item) => { 
        return item.username == tel && item.password == pass;

    })
    if (p) { 
        res.send("注册成功")
    } else {
        console.log("登录失败");
    }
})
// 暴露router
module.exports = router;